#!/usr/bin/env python2.6
#


"""A convenience wrapper for starting gcutil."""



import os
import platform
import subprocess
import sys

# Checks the Python version.
if not hasattr(sys, 'version_info'):
  sys.stderr.write('Very old versions of Python are not supported. Please '
                   'use version 2.6 or greater.\n')
  sys.exit(1)
if tuple(sys.version_info[:2]) < (2, 6):
  sys.stderr.write('Python %d.%d is not supported. Please use version 2.6 '
                   'or greater.\n' % tuple(sys.version_info[:2]))
  sys.exit(1)


def main():
  """Launches gcutil using python -S.

  The -S ensures that the site module is not imported and eliminates a
  class of problems that can occur when the user's system has multiple
  versions of a library.
  """
  python_bin = sys.executable
  if not python_bin:
    sys.stderr.write('Could not find Python executable.')
    sys.exit(1)

  gcutil_main = os.path.join(
      os.path.dirname(os.path.realpath(__file__)),
      'lib',
      'google_compute_engine',
      'gcutil_lib',
      'run_static_gcutil.py')
  args = [python_bin, '-S', gcutil_main] + sys.argv[1:]
  if platform.system() == 'Windows':
    subprocess.Popen(args).wait()
  else:
    os.execv(python_bin, args)


if __name__ == '__main__':
  main()
